import 'package:api/pages/provider/getX/demo/count/count_controller.dart';
import 'package:api/pages/provider/getX/demo/obs/obs_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CountHomePage extends StatefulWidget {
  @override
  _CountHomePageState createState() => _CountHomePageState();
}

class _CountHomePageState extends State<CountHomePage> {
  int _count = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('setState计数器')),
      body: Column(
        children: [
          buildColumn1(),
          SizedBox(height: 30),
          buildColumn2(),
          SizedBox(height: 30),
          buildColumn3(),
          SizedBox(height: 30),
          buildColumn4()
        ],
      ),
    );
  }

  buildColumn1() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text("当前显示计数 $_count"),
        SizedBox(
          height: 30,
        ),
        ElevatedButton(
          onPressed: () {
            _count++;
            setState(() {});
          },
          child: Text("getx添加"),
        ),
      ],
    );
  }

  buildColumn2() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        GetBuilder<CountController>(
            init: CountController(),
            builder: (CountController controller) {
              return Text("当前显示计数 ${controller.count}");
            }),
        SizedBox(
          height: 30,
        ),
        ElevatedButton(
          onPressed: () {
            Get.find<CountController>().add();
          },
          child: Text("添加"),
        ),
      ],
    );
  }

  buildColumn3() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        GetBuilder<CountController>(
            init: CountController(),
            id: 'count2',
            builder: (CountController controller) {
              return Text("当前显示计数 ${controller.count2}");
            }),
        SizedBox(
          height: 30,
        ),
        ElevatedButton(
          onPressed: () {
            Get.find<CountController>().addCount2();
          },
          child: Text("添加"),
        ),
      ],
    );
  }

  buildColumn4() {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        ElevatedButton(
          onPressed: () {
            Get.to(() => new ObsHomePage());
          },
          child: Text("进入"),
        ),
      ],
    );
  }
}
